window.onload = function() { window.onload; grilla_inicio() };

function grilla_inicio()
{
	//buscar captions y ponerle el evento
	var tablas = document.getElementsByTagName("table");
	for( i=0; i<tablas.length; i++ )
	{
		if( tablas[i].className == 'grilla' ) 
		{
			var caption = tablas[i].getElementsByTagName("caption")[0];
			caption.onclick = function() { caption_click( this.parentNode ); };
		}
	}
}

function caption_click( grilla )
{
	if( estaCerrada( grilla ) )
	{
		mostrar( grilla );
	}
	else
	{
		cerrar( grilla );
	}
}

function mostrar( grilla )
{
	var h = grilla.getElementsByTagName("thead")[0];
	var f = grilla.getElementsByTagName("tfoot")[0];
	var	b = grilla.getElementsByTagName("tbody")[0];
	h.style.display = "block";
	f.style.display = "block";
	b.style.display = "block";
}

function cerrar( grilla )
{
	var h = grilla.getElementsByTagName("thead")[0];
	var f = grilla.getElementsByTagName("tfoot")[0];
	var	b = grilla.getElementsByTagName("tbody")[0];
	h.style.display = "none";
	f.style.display = "none";
	b.style.display = "none";
}

function estaCerrada( grilla )
{
	var h = grilla.getElementsByTagName("thead")[0];
	return h.style.display != "block";
}